//
//  HTTPDownloader.h
//  qw-troad-ios
//
//  Created by Yunhai.Wu on 15/8/14.
//  Copyright (c) 2015年 117go. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "QWHTTPDownloaderConfig.h"

typedef void (^QWDownloadFinishBlock)(NSData *data);
typedef void (^QWDownloadFailBlock)(NSError *error);
typedef void (^QWDownloadProgressBlock)(float progress);

/**
 *  取消所有下载通知
 */
extern NSString *const QWHTTPDownloaderCancelAllNotification;

/**
 *  HTTP 下载器
 */
@interface QWHTTPDownloader : NSObject
@property (nonatomic, assign, readonly) BOOL cache;//是否缓存下载内容，default yes
@property (nonatomic, assign) NSTimeInterval timeoutInterval;//default 100 秒
@property (nonatomic, assign, readonly) BOOL downloading;//是否正在下载

/**
 *  异步下载
 *
 *  @param url           文件url
 *  @param finishBlock   下载完成block
 *  @param errorBlock    下载错误block
 *  @param progressBlock 下载进度block
 *  @param cache         是否缓存
 */
-(void) asynDownload:(NSString*) url finish:(QWDownloadFinishBlock) finishBlock error:(QWDownloadFailBlock) errorBlock progress:(QWDownloadProgressBlock) progressBlock cache:(BOOL) cache;

/**
 *  同步下载
 *
 *  @param url         文件url
 *  @param finishBlock 下载完成block
 *  @param errorBlock  下载错误block
 *  @param cache       是否缓存
 */
-(void) syncDownload:(NSString*) url finish:(QWDownloadFinishBlock) finishBlock error:(QWDownloadFailBlock) errorBlock cache:(BOOL) cache;

-(void) cancel;//取消
+(void) cancelAll;//取消所有下载
+(instancetype) instance;//实例化一个新HTTPDownloader
@end
